$(function () {
    page("home");
});

function page(type) {
    findAll();
    let total = $("#total").text();// 总条数
    total = parseInt(total);
    let pageSize = $("#pageSize").val(); // 每页显示条数
    pageSize = parseInt(pageSize);
    let pageNum = $("#pageNum").val(); // 当前页
    pageNum = parseInt(pageNum);
    let totalNum = Math.ceil(total / pageSize);
    totalNum = totalNum;
    $("#totalNum").text(totalNum);// 总页数
    console.log(total);
    console.log(pageSize);
    console.log(pageNum);
    console.log(totalNum);
    switch (type) {
        case 'go':
            if (pageNum > totalNum) {
                pageNum = totalNum;
            } else if (pageNum < 1) {
                pageNum = 1;
            }
            break;
        case 'home':
            pageNum = 1;
            break;
        case 'previous':
            pageNum--;
            if (pageNum < 1)
                pageNum++;
            /*if (pageNum != 1) {
                pageNum = pageNum - 1;
            }*/
            break;
        case 'next':
            pageNum++;
            if (pageNum > totalNum) {
                pageNum = totalNum;
            }
            break;
        case 'last':
            pageNum = totalNum;
            break;

    }
    $("#pageNum").val(pageNum);
    findAll();
}